/*
 * @Author: wangzm
 * @Date: 2020-01-07 09:10:25
 * @LastEditors: xlm
 * @LastEditTime: 2021-08-09 15:41:37
 * @Description: file content
 */
import Vue from 'vue'
// import JsEncrypt from 'jsencrypt'
import App from './App'
import Api from '@/apis'
import request from '@/utils/request'
import globalComponents from '@/components/global/global-components.vue'
import basePageView from '@/components/base/base-page-view.vue'
import baseListState from '@/components/base/base-list-state.vue'
import baseNav from '@/components/base/base-nav.vue'
import basePopup from '@/components/base/base-popup.vue'
import bOpenType from '@/components/base/base-open-type.vue'
import bImage from '@/components/base/base-image.vue'
import urlImage from '@/components/base/base-url-image.vue'
import confirmPopup from '@/components/confirmPopup/index'
import bText from '@/components/base/base-text.vue'
import noMore from '@/components/base/no-more.vue'
import bChecked from '@/components/bsnl/checked.vue'
import bButton from '@/components/bsnl/button.vue'
import store from './stores/index'
import { queryPageParam, queryShareOption, log, callPhone, downloadFile } from './utils/tools'
import { navigateTo,toBackPage } from './utils/navigateTo'
import { msg } from './utils/utils'
import JsEncrypt from './utils/jsencrypt'
import * as utils from './utils/utils'
import './plugins/filters'
import './plugins/common'
import uView from "./uview-ui";
Vue.use(uView);
// #ifdef H5
import Bridge from './plugins/JSBridge'
import './plugins/ARMS'
// #endif
import { sensorTrack } from './plugins/sensor'
import trackSDK from './plugins/BSNLAnalyticsSDK'
import './styles/index.scss'

// 移动端网页调试工具，有需要可以开启
// #ifdef H5
import VConsole from 'vconsole'
if (process.env.VUE_APP_BUILD_TYPE !== 'PROD') {
  const vConsole = new VConsole()
  Vue.use(vConsole)
}
// #endif
// 忽略自定义元素标签抛出的报错
Vue.config.ignoredElements = [
  ...Vue.config.ignoredElements,
  'wx-open-launch-app',
  'wx-open-launch-weapp'
]

/* eslint-disable */
// 获取上一页面实例
const prePage = (pageIndex = 2, type) => {
  const pages = getCurrentPages()
  const prePage = pages[pages.length - pageIndex]
  if (prePage && type === 'route') {
    return prePage.route
  }
  // #ifdef H5
  return prePage
  // #endif
  return prePage.$vm
}
/* eslint-disable-end */
const errorHandler = (err, vm, info) => {
  log({ err, info })
}
Vue.config.productionTip = false
Vue.config.errorHandler = errorHandler
Vue.prototype.$sensorTrack = sensorTrack // 埋点
Vue.prototype.$trackSDK = trackSDK // 埋点
Vue.prototype.$store = store
Vue.prototype.$api = Api
Vue.prototype.$gc = {}
Vue.prototype.$prePage = prePage
Vue.prototype.$navigateTo = navigateTo
Vue.prototype.$queryPageParam = queryPageParam
Vue.prototype.$queryShareOption = queryShareOption
Vue.prototype.$callPhone = callPhone
Vue.prototype.$downloadFile = downloadFile
Vue.prototype.$errorHandler = errorHandler
Vue.prototype.$request = request
Vue.prototype.$msg = msg
Vue.prototype.$utils = utils
Vue.prototype.$toBackPage = toBackPage
// rsa加解密
Vue.prototype.$jsEncrypt = JsEncrypt
uni.getSystemInfo({
  success: (res) => {
    Vue.prototype.$statusBarHeight = res.statusBarHeight
  }
})
// #ifdef H5
Vue.prototype.$Bridge = Bridge
if(Bridge.isInWeChat){
  Bridge.setWeChatConfig()
}
// #endif
Vue.prototype.$appName = () => {
  return '碧选'
}
// 设置来源标题
Vue.prototype.$setNavTitle = (title, isHide = false) => {
  if(title){
    uni.setNavigationBarTitle({ title })
    // #ifdef H5
    sensorTrack('webPageView', {
      web_url: location.href,
      web_title: title
    })
    // #endif
  }

  // #ifdef H5
  if(Bridge.isInApp){
    const data = {
      type: 'setTitle',
      data: { title, isHide }
    }
    Bridge.callHandler(data)
  }
  // #endif
}

Vue.component('cGlobal', globalComponents)
Vue.component('basePageView', basePageView)
Vue.component('baseListState', baseListState)
Vue.component('baseNav', baseNav)
Vue.component('basePopup', basePopup)
Vue.component('bOpenType', bOpenType)
Vue.component('bImage', bImage)
Vue.component('url-image', urlImage)
Vue.component('confirmPopup', confirmPopup)
Vue.component('bText', bText)
Vue.component('noMore', noMore)
Vue.component('bChecked', bChecked)
Vue.component('bButton', bButton)
App.mpType = 'app'

const app = new Vue({
  store,
  ...App
})
app.$mount()
